package com.web.common.dataDictionary.PO;

import java.util.*;
import com.css.sword.kernel.base.annotation.*;
import com.css.sword.kernel.base.dataElement.*;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;

import com.web.common.dataDictionary.DE.DE_ID;
import com.web.common.dataDictionary.DE.DE_USERNAME;
import com.web.common.dataDictionary.DE.DE_PASSWORD;
import com.web.common.dataDictionary.DE.DE_LXDH;
import com.web.common.dataDictionary.DE.DE_EMAIL;
import com.web.common.dataDictionary.DE.DE_SHZT;
import com.web.common.dataDictionary.DE.DE_SHSJ;
import com.web.common.dataDictionary.DE.DE_ISHMD;
import com.web.common.dataDictionary.DE.DE_JRHMDSJ;
import com.web.common.dataDictionary.DE.DE_OPPTIME;
import com.web.common.dataDictionary.DE.DE_VIPSYTS;
import com.web.common.dataDictionary.DE.DE_SHFJ;


/**
 * web用户表
 */
@PersistObject
public class TabUserPO extends AbsPersistObject {
	//private static final long serialVersionUID = 5598945566497944380L;
	private static final long serialVersionUID = 1L;
	private static final Map<String, Integer> fieldIndex = new HashMap<String, Integer>(12);
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(12);
	
	static{
		HAS_DEFAULT_VALUE.set(7, true);HAS_DEFAULT_VALUE.set(10, true);
		fieldIndex.put("id",0);fieldIndex.put("username",1);fieldIndex.put("password",2);fieldIndex.put("lxdh",3);fieldIndex.put("email",4);fieldIndex.put("shzt",5);fieldIndex.put("shsj",6);fieldIndex.put("ishmd",7);fieldIndex.put("jrhmdsj",8);fieldIndex.put("opptime",9);fieldIndex.put("vipsyts",10);fieldIndex.put("shfj",11);
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "tab_user";

	/**
	 * 主键id
	 */
	private DE_ID id = DE_ID.getTemplateInstance();

	/**
	 * 用户名
	 */
	private DE_USERNAME username = DE_USERNAME.getTemplateInstance();

	/**
	 * 密码
	 */
	private DE_PASSWORD password = DE_PASSWORD.getTemplateInstance();

	/**
	 * 联系电话
	 */
	private DE_LXDH lxdh = DE_LXDH.getTemplateInstance();

	/**
	 * 邮箱
	 */
	private DE_EMAIL email = DE_EMAIL.getTemplateInstance();

	/**
	 * 审核状态
	 */
	private DE_SHZT shzt = DE_SHZT.getTemplateInstance();

	/**
	 * 审核时间
	 */
	private DE_SHSJ shsj = DE_SHSJ.getTemplateInstance();

	/**
	 * 是否在黑名单中
	 */
	private DE_ISHMD ishmd = DE_ISHMD.getTemplateInstance();

	/**
	 * 加入黑名单日期
	 */
	private DE_JRHMDSJ jrhmdsj = DE_JRHMDSJ.getTemplateInstance();

	/**
	 * 操作时间
	 */
	private DE_OPPTIME opptime = DE_OPPTIME.getTemplateInstance();

	/**
	 * vip剩余天数
	 */
	private DE_VIPSYTS vipsyts = DE_VIPSYTS.getTemplateInstance();

	/**
	 * 审核附件
	 */
	private DE_SHFJ shfj = DE_SHFJ.getTemplateInstance();


	public TabUserPO(){
		this.insertState = new BitSet(12);
		this.updateState = new BitSet(12);
	}

	
	/**
	 * 获取 "主键id" 值
	 */	
	public DE_ID getId(){
		return  id;
	}
	
	/**
	 * 设置 "主键id" 值
	 */
	public void setId(DE_ID id) {
		if(id == null){
			id= DE_ID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.id = id;
	}
	
	/**
	 * 获取 "用户名" 值
	 */	
	public DE_USERNAME getUsername(){
		return  username;
	}
	
	/**
	 * 设置 "用户名" 值
	 */
	public void setUsername(DE_USERNAME username) {
		if(username == null){
			username= DE_USERNAME.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.username = username;
	}
	
	/**
	 * 获取 "密码" 值
	 */	
	public DE_PASSWORD getPassword(){
		return  password;
	}
	
	/**
	 * 设置 "密码" 值
	 */
	public void setPassword(DE_PASSWORD password) {
		if(password == null){
			password= DE_PASSWORD.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.password = password;
	}
	
	/**
	 * 获取 "联系电话" 值
	 */	
	public DE_LXDH getLxdh(){
		return  lxdh;
	}
	
	/**
	 * 设置 "联系电话" 值
	 */
	public void setLxdh(DE_LXDH lxdh) {
		if(lxdh == null){
			lxdh= DE_LXDH.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.lxdh = lxdh;
	}
	
	/**
	 * 获取 "邮箱" 值
	 */	
	public DE_EMAIL getEmail(){
		return  email;
	}
	
	/**
	 * 设置 "邮箱" 值
	 */
	public void setEmail(DE_EMAIL email) {
		if(email == null){
			email= DE_EMAIL.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.email = email;
	}
	
	/**
	 * 获取 "审核状态" 值
	 */	
	public DE_SHZT getShzt(){
		return  shzt;
	}
	
	/**
	 * 设置 "审核状态" 值
	 */
	public void setShzt(DE_SHZT shzt) {
		if(shzt == null){
			shzt= DE_SHZT.getTemplateInstance();
		}
		recordChangeFlag(5);
		this.shzt = shzt;
	}
	
	/**
	 * 获取 "审核时间" 值
	 */	
	public DE_SHSJ getShsj(){
		return  shsj;
	}
	
	/**
	 * 设置 "审核时间" 值
	 */
	public void setShsj(DE_SHSJ shsj) {
		if(shsj == null){
			shsj= DE_SHSJ.getTemplateInstance();
		}
		recordChangeFlag(6);
		this.shsj = shsj;
	}
	
	/**
	 * 获取 "是否在黑名单中" 值
	 */	
	public DE_ISHMD getIshmd(){
		return  ishmd;
	}
	
	/**
	 * 设置 "是否在黑名单中" 值
	 */
	public void setIshmd(DE_ISHMD ishmd) {
		if(ishmd == null){
			ishmd= DE_ISHMD.getTemplateInstance();
		}
		recordChangeFlag(7);
		this.ishmd = ishmd;
	}
	
	/**
	 * 获取 "加入黑名单日期" 值
	 */	
	public DE_JRHMDSJ getJrhmdsj(){
		return  jrhmdsj;
	}
	
	/**
	 * 设置 "加入黑名单日期" 值
	 */
	public void setJrhmdsj(DE_JRHMDSJ jrhmdsj) {
		if(jrhmdsj == null){
			jrhmdsj= DE_JRHMDSJ.getTemplateInstance();
		}
		recordChangeFlag(8);
		this.jrhmdsj = jrhmdsj;
	}
	
	/**
	 * 获取 "操作时间" 值
	 */	
	public DE_OPPTIME getOpptime(){
		return  opptime;
	}
	
	/**
	 * 设置 "操作时间" 值
	 */
	public void setOpptime(DE_OPPTIME opptime) {
		if(opptime == null){
			opptime= DE_OPPTIME.getTemplateInstance();
		}
		recordChangeFlag(9);
		this.opptime = opptime;
	}
	
	/**
	 * 获取 "vip剩余天数" 值
	 */	
	public DE_VIPSYTS getVipsyts(){
		return  vipsyts;
	}
	
	/**
	 * 设置 "vip剩余天数" 值
	 */
	public void setVipsyts(DE_VIPSYTS vipsyts) {
		if(vipsyts == null){
			vipsyts= DE_VIPSYTS.getTemplateInstance();
		}
		recordChangeFlag(10);
		this.vipsyts = vipsyts;
	}
	
	/**
	 * 获取 "审核附件" 值
	 */	
	public DE_SHFJ getShfj(){
		return  shfj;
	}
	
	/**
	 * 设置 "审核附件" 值
	 */
	public void setShfj(DE_SHFJ shfj) {
		if(shfj == null){
			shfj= DE_SHFJ.getTemplateInstance();
		}
		recordChangeFlag(11);
		this.shfj = shfj;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {id,username,password,lxdh,email,shzt,shsj,ishmd,jrhmdsj,opptime,vipsyts,shfj};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"id","username","password","lxdh","email","shzt","shsj","ishmd","jrhmdsj","opptime","vipsyts","shfj"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
		switch (index) {
		case 0 : return id;
		case 1 : return username;
		case 2 : return password;
		case 3 : return lxdh;
		case 4 : return email;
		case 5 : return shzt;
		case 6 : return shsj;
		case 7 : return ishmd;
		case 8 : return jrhmdsj;
		case 9 : return opptime;
		case 10 : return vipsyts;
		case 11 : return shfj;
 
		default:
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
	}
	
	@Override
	public TabUserPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}

		switch (index) {

				case 0 : {
					if (fieldValue == null) {
						setId(null);
					} else {
						setId((DE_ID) fieldValue);
					}
					return this;
				}
				
				case 1 : {
					if (fieldValue == null) {
						setUsername(null);
					} else {
						setUsername((DE_USERNAME) fieldValue);
					}
					return this;
				}
				
				case 2 : {
					if (fieldValue == null) {
						setPassword(null);
					} else {
						setPassword((DE_PASSWORD) fieldValue);
					}
					return this;
				}
				
				case 3 : {
					if (fieldValue == null) {
						setLxdh(null);
					} else {
						setLxdh((DE_LXDH) fieldValue);
					}
					return this;
				}
				
				case 4 : {
					if (fieldValue == null) {
						setEmail(null);
					} else {
						setEmail((DE_EMAIL) fieldValue);
					}
					return this;
				}
				
				case 5 : {
					if (fieldValue == null) {
						setShzt(null);
					} else {
						setShzt((DE_SHZT) fieldValue);
					}
					return this;
				}
				
				case 6 : {
					if (fieldValue == null) {
						setShsj(null);
					} else {
						setShsj((DE_SHSJ) fieldValue);
					}
					return this;
				}
				
				case 7 : {
					if (fieldValue == null) {
						setIshmd(null);
					} else {
						setIshmd((DE_ISHMD) fieldValue);
					}
					return this;
				}
				
				case 8 : {
					if (fieldValue == null) {
						setJrhmdsj(null);
					} else {
						setJrhmdsj((DE_JRHMDSJ) fieldValue);
					}
					return this;
				}
				
				case 9 : {
					if (fieldValue == null) {
						setOpptime(null);
					} else {
						setOpptime((DE_OPPTIME) fieldValue);
					}
					return this;
				}
				
				case 10 : {
					if (fieldValue == null) {
						setVipsyts(null);
					} else {
						setVipsyts((DE_VIPSYTS) fieldValue);
					}
					return this;
				}
				
				case 11 : {
					if (fieldValue == null) {
						setShfj(null);
					} else {
						setShfj((DE_SHFJ) fieldValue);
					}
					return this;
				}
				
		default:
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}
	
	}

	@Override
	protected TabUserPO clone() {
		TabUserPO t = new TabUserPO();
		
		t.setId(this.id);
		t.setUsername(this.username);
		t.setPassword(this.password);
		t.setLxdh(this.lxdh);
		t.setEmail(this.email);
		t.setShzt(this.shzt);
		t.setShsj(this.shsj);
		t.setIshmd(this.ishmd);
		t.setJrhmdsj(this.jrhmdsj);
		t.setOpptime(this.opptime);
		t.setVipsyts(this.vipsyts);
		t.setShfj(this.shfj);

		return t;
	}

	@Override
	public TabUserPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("id")){
			value = dataMap.get("id");
			
			if (value == null) {
				this.setId(null);
			} else {
				if (value instanceof DE_ID) {
					this.setId((DE_ID) value);
				}
			    else {
					this.setId(new DE_ID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("username")){
			value = dataMap.get("username");
			
			if (value == null) {
				this.setUsername(null);
			} else {
				if (value instanceof DE_USERNAME) {
					this.setUsername((DE_USERNAME) value);
				}
			    else {
					this.setUsername(new DE_USERNAME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("password")){
			value = dataMap.get("password");
			
			if (value == null) {
				this.setPassword(null);
			} else {
				if (value instanceof DE_PASSWORD) {
					this.setPassword((DE_PASSWORD) value);
				}
			    else {
					this.setPassword(new DE_PASSWORD(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("lxdh")){
			value = dataMap.get("lxdh");
			
			if (value == null) {
				this.setLxdh(null);
			} else {
				if (value instanceof DE_LXDH) {
					this.setLxdh((DE_LXDH) value);
				}
			    else {
					this.setLxdh(new DE_LXDH(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("email")){
			value = dataMap.get("email");
			
			if (value == null) {
				this.setEmail(null);
			} else {
				if (value instanceof DE_EMAIL) {
					this.setEmail((DE_EMAIL) value);
				}
			    else {
					this.setEmail(new DE_EMAIL(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("shzt")){
			value = dataMap.get("shzt");
			
			if (value == null) {
				this.setShzt(null);
			} else {
				if (value instanceof DE_SHZT) {
					this.setShzt((DE_SHZT) value);
				}
			    else {
					this.setShzt(new DE_SHZT(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("shsj")){
			value = dataMap.get("shsj");
			
			if (value == null) {
				this.setShsj(null);
			} else {
				if (value instanceof DE_SHSJ) {
					this.setShsj((DE_SHSJ) value);
				}
				else if(value instanceof java.util.Date){
					this.setShsj(new DE_SHSJ((java.util.Date)value));
				}
			    else {
					this.setShsj(new DE_SHSJ(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("ishmd")){
			value = dataMap.get("ishmd");
			
			if (value == null) {
				this.setIshmd(null);
			} else {
				if (value instanceof DE_ISHMD) {
					this.setIshmd((DE_ISHMD) value);
				}
			    else {
					this.setIshmd(new DE_ISHMD(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("jrhmdsj")){
			value = dataMap.get("jrhmdsj");
			
			if (value == null) {
				this.setJrhmdsj(null);
			} else {
				if (value instanceof DE_JRHMDSJ) {
					this.setJrhmdsj((DE_JRHMDSJ) value);
				}
				else if(value instanceof java.util.Date){
					this.setJrhmdsj(new DE_JRHMDSJ((java.util.Date)value));
				}
			    else {
					this.setJrhmdsj(new DE_JRHMDSJ(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("opptime")){
			value = dataMap.get("opptime");
			
			if (value == null) {
				this.setOpptime(null);
			} else {
				if (value instanceof DE_OPPTIME) {
					this.setOpptime((DE_OPPTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setOpptime(new DE_OPPTIME((java.util.Date)value));
				}
			    else {
					this.setOpptime(new DE_OPPTIME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("vipsyts")){
			value = dataMap.get("vipsyts");
			
			if (value == null) {
				this.setVipsyts(null);
			} else {
				if (value instanceof DE_VIPSYTS) {
					this.setVipsyts((DE_VIPSYTS) value);
				}
			    else {
					this.setVipsyts(new DE_VIPSYTS(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("shfj")){
			value = dataMap.get("shfj");
			
			if (value == null) {
				this.setShfj(null);
			} else {
				if (value instanceof DE_SHFJ) {
					this.setShfj((DE_SHFJ) value);
				}
			    else {
					this.setShfj(new DE_SHFJ(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("id", id);
		dataMap.put("username", username);
		dataMap.put("password", password);
		dataMap.put("lxdh", lxdh);
		dataMap.put("email", email);
		dataMap.put("shzt", shzt);
		dataMap.put("shsj", shsj);
		dataMap.put("ishmd", ishmd);
		dataMap.put("jrhmdsj", jrhmdsj);
		dataMap.put("opptime", opptime);
		dataMap.put("vipsyts", vipsyts);
		dataMap.put("shfj", shfj);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("id", (id==null?null:id.value));
		dataMap.put("username", (username==null?null:username.value));
		dataMap.put("password", (password==null?null:password.value));
		dataMap.put("lxdh", (lxdh==null?null:lxdh.value));
		dataMap.put("email", (email==null?null:email.value));
		dataMap.put("shzt", (shzt==null?null:shzt.value));
		dataMap.put("shsj", (shsj==null?null:shsj.value));
		dataMap.put("ishmd", (ishmd==null?null:ishmd.value));
		dataMap.put("jrhmdsj", (jrhmdsj==null?null:jrhmdsj.value));
		dataMap.put("opptime", (opptime==null?null:opptime.value));
		dataMap.put("vipsyts", (vipsyts==null?null:vipsyts.value));
		dataMap.put("shfj", (shfj==null?null:shfj.value));
		
		return dataMap;
	}
	
	@Override
	public TabUserPO newInstance() {
		return new TabUserPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{id};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (id.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段id不允许为空\n");
				}
				if (username.value == null && !HAS_DEFAULT_VALUE.get(1)) {
					errorMsg.append("字段username不允许为空\n");
				}
				if (password.value == null && !HAS_DEFAULT_VALUE.get(2)) {
					errorMsg.append("字段password不允许为空\n");
				}
				if (email.value == null && !HAS_DEFAULT_VALUE.get(4)) {
					errorMsg.append("字段email不允许为空\n");
				}
				if (shzt.value == null && !HAS_DEFAULT_VALUE.get(5)) {
					errorMsg.append("字段shzt不允许为空\n");
				}
				if (ishmd.value == null && !HAS_DEFAULT_VALUE.get(7)) {
					errorMsg.append("字段ishmd不允许为空\n");
				}
				if (opptime.value == null && !HAS_DEFAULT_VALUE.get(9)) {
					errorMsg.append("字段opptime不允许为空\n");
				}
				if (vipsyts.value == null && !HAS_DEFAULT_VALUE.get(10)) {
					errorMsg.append("字段vipsyts不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && id.value == null) {
			errorMsg.append("字段id不允许为空\n");
		}
		if (updateState.get(1) && username.value == null) {
			errorMsg.append("字段username不允许为空\n");
		}
		if (updateState.get(2) && password.value == null) {
			errorMsg.append("字段password不允许为空\n");
		}
		if (updateState.get(4) && email.value == null) {
			errorMsg.append("字段email不允许为空\n");
		}
		if (updateState.get(5) && shzt.value == null) {
			errorMsg.append("字段shzt不允许为空\n");
		}
		if (updateState.get(7) && ishmd.value == null) {
			errorMsg.append("字段ishmd不允许为空\n");
		}
		if (updateState.get(9) && opptime.value == null) {
			errorMsg.append("字段opptime不允许为空\n");
		}
		if (updateState.get(10) && vipsyts.value == null) {
			errorMsg.append("字段vipsyts不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("id:").append(id.value!=null?id:"").append(" ").append("username:").append(username.value!=null?username:"").append(" ").append("password:").append(password.value!=null?password:"").append(" ").append("lxdh:").append(lxdh.value!=null?lxdh:"").append(" ").append("email:").append(email.value!=null?email:"").append(" ").append("shzt:").append(shzt.value!=null?shzt:"").append(" ").append("shsj:").append(shsj.value!=null?shsj:"").append(" ").append("ishmd:").append(ishmd.value!=null?ishmd:"").append(" ").append("jrhmdsj:").append(jrhmdsj.value!=null?jrhmdsj:"").append(" ").append("opptime:").append(opptime.value!=null?opptime:"").append(" ").append("vipsyts:").append(vipsyts.value!=null?vipsyts:"").append(" ").append("shfj:").append(shfj.value!=null?shfj:"").append(" ");
		return str.toString();
	}
	
}
